package com.fowo.api.syncLingxingApi.entity;

import cn.hutool.core.util.ObjUtil;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fowo.api.user.model.JwtUserInfo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

@DS("ds24")
@Data
public class TmpSyncLingxingToAuxBase implements Serializable {

    private static final long serialVersionUID = 1L;
    @TableId
    @TableField(value = "id")
    @Schema(title = "主键")
    @JSONField(name = "id")
    private Long id;

    @Schema(title = "sku")
    @TableField("sku")
    @JSONField(name = "sku")
    private String sku;

    @TableField(value = "create_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Schema(title = "创建时间")
    @JSONField(name = "create_time", serialize = false, deserialize = false)
    private Date createTime;

    @TableField(value = "create_user")
    @Schema(title = "创建人")
    @JSONField(name = "create_user", serialize = false, deserialize = false)
    private Long createUser;

    @TableField(value = "last_update_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Schema(title = "更新时间")
    @JSONField(name = "last_update_time", serialize = false, deserialize = false)
    private Date lastUpdateTime;

    @TableField(value = "last_update_user")
    @Schema(title = "更新人")
    @JSONField(name = "last_update_user", serialize = false, deserialize = false)
    private Long lastUpdateUser;

    @TableField(value = "_version")
    @Schema(title = "版本号")
    @JSONField(name = "_version", serialize = false, deserialize = false)
    private String _version;


    @TableField(value = "_flag")
    @Schema(title = "删除标记")
    @JSONField(name = "_flag", serialize = false, deserialize = false)
    private Integer _flag;

    public TmpSyncLingxingToAuxBase() {
        init();
    }

    public void init() {
        JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
        try {
            if (ObjUtil.isNotEmpty(jwtUserInfo)) {
                this.setCreateUser(jwtUserInfo.getUserId());
                this.setLastUpdateUser(jwtUserInfo.getUserId());
            }
            this.setCreateTime(new Date());
            this.setLastUpdateTime(new Date());
            this.set_flag(2);
        } catch (Exception e) {
        }
    }
}